<?php
error_reporting(E_ALL);

include_once '../common_classes.php';

$firsttimestamp = 1257986807;
$lasttimestamp = 1259323516;
$interval = 1800; // 30 minutes
$print = "";

connectDB();

//mysql_query("CREATE TEMPORARY TABLE tmp_time (stamp int);");

for($i = $firsttimestamp; $i < $lasttimestamp + $interval; $i = $i + $interval) {
	$q = "INSERT INTO tmp_time VALUES($i);";
	mysql_query($q);
	echo $q . '<br />';
}


	$print = $print . date('Y-m-d H:i', $i) . ', ';
	/*$result = mysql_query(getQuery($i, true));// || die(mysql_error());
	
	$row = mysql_fetch_array($result);
	$print = $print . $row[0] . '<br />';*/
	
	
echo $print;
echo 'finished';
mysql_close();
function getQuery($time, $distinct) {
	$query = "";
	
	if($distinct == true)
		$query = "SELECT COUNT(DISTINCT voter_ip) FROM Votes WHERE Votes.timestamp <= $time;";
	else
		$query = "SELECT COUNT(DISTINCT voter_ip, Votes.timestamp) FROM Votes WHERE Votes.timestamp <= $time;";
		
	$query = "SELECT COUNT(DISTINCT voter_ip), stamp FROM Votes RIGHT JOIN tmp_time ON Votes.timestamp <= tmp_time.stamp GROUP BY tmp_time.stamp;";
		
	return $query;

}
?>